<?php

		
	$logid=GetLoginUserID();
		
	if(!$logid)
		edp_redirect(edp_href_link(PAGENAME_PAGE_NOT_FOUND));
		
	//或者用user_id为0的推荐
	$recommendDAO=GetRecommendDAO();
	//Get recommended C2C shops
	$C2CshopList=$recommendDAO->GetRecommendC2CshopByUid($logid);
	
	//Get recommended B2C shops
	$B2CshopList=$recommendDAO->GetRecommendB2CShopByUid($logid);
	
	//Get recommended reviews
	$reviewList=$recommendDAO->GetRecommendReviewByUid($logid);
	
	//Get recommended products
	$productList = $recommendDAO->GetRecommendProductByUid($logid);
	
	//Get friends' recent event
	$friendDAO=GetFriendDAO();
	$userDAO=GetUserDAO();
	$listDAO=GetListDAO();
	$shopDAO=GetShopDAO();
	$productDAO = GetProductDAO();
	$result=$friendDAO->GetFriendEventByUid($logid, 25);

	if($result)
	{
		foreach($result as $key=>$event)
		{
			$action = explode(',',$event['action']);
						
			switch ($action[0])
			{
				case REGISTER:
				{
					$event['html']='<a href="'.edp_href_link(PAGENAME_USER_INFO, 'uid='.$event['user_id']).'">'.$event['nick'].
					'</a>在本站注册。';
					break;
				}
				case INVITE_FRIEND_SUCCESS:
				{
					$user=$userDAO->GetUserByID($event['parameters']);
					if($user!=false)
					{
						$event['html']='<a href="'.edp_href_link(PAGENAME_USER_INFO, 'uid='.$event['user_id']).'">'.$event['nick'].
						'</a>成功邀请用户 <a href="'.edp_href_link(PAGENAME_USER_INFO,'uid='.$event['parameters']).'">'.$user['nick'].'</a> 注册。';
					}
					break;
				}
				case CREATE_LIST:
				{
					$list=$listDAO->GetListByLid($event['parameters']);
					if($list!=false)
					{
						$event['html']='<a href="'.edp_href_link(PAGENAME_USER_INFO, 'uid='.$event['user_id']).'">'.$event['nick'].
						'</a>创建评单 <a href="'.edp_href_link(PAGENAME_LIST_INFO,'lid='.$event['parameters']).'">'.$list['title'].'</a>。';
					}
					break;
				}
				case COLLECT_LIST:
				{
					if($list!=false)
					{
						$list=$listDAO->GetListByLid($event['parameters']);
						$event['html']='<a href="'.edp_href_link(PAGENAME_USER_INFO, 'uid='.$event['user_id']).'">'.$event['nick'].
						'</a>收藏评单 <a href="'.edp_href_link(PAGENAME_LIST_INFO,'lid='.$event['parameters']).'">'.
						$list['title'].'</a>。';
					}
					break;
				}				
				
				//Review about shop
				case NORMAL_REVIEW:
				{			
					$idlist=split(' ',$event['parameters']);					
					$is_picture='';
					$is_first='';

					foreach($action as $k=>$v){
						
						if($v==REVIEW_INCLUDE_PIC){
							
							$is_picture = '[图]';
						}
						if($v==FIRST_REVIEW){
							
							$is_first = '第一次';
						}
					}					
					
					if(isset($idlist[2])){
						//存在product_id,表示是在商品页面发表的点评，显示商品信息
					
						$productName=$productDAO->GetProductName($idlist[2]);
						if($productName!=false)
						{
							$event['html']='<a href="'.edp_href_link(PAGENAME_USER_INFO, 'uid='.$event['user_id']).'">'.$event['nick'].
							'</a>对商品 <a href="'.edp_href_link(PAGENAME_PRODUCT_INFO,'pid='.$idlist[2]).'">'.$productName.'</a> 发表'.$is_first.'评论。'.$is_picture;
						}
						
					}else{
						
						//不存在product_id,表示是在店铺页面发表的点评，显示店铺信息
						$shopName=$shopDAO->GetShopName($idlist[0]);
						if($shopName!=false)
						{
							$event['html']='<a href="'.edp_href_link(PAGENAME_USER_INFO, 'uid='.$event['user_id']).'">'.$event['nick'].
							'</a>对店铺 <a href="'.edp_href_link(PAGENAME_SHOP_INFO,'sid='.$idlist[0]).'">'.$shopName.'</a> 发表'.$is_first.'评论。'.$is_picture;
						}
					
					}
					
					break;
				}

				case ADD_SHOP:
				{
					$shopName=$shopDAO->GetShopName($event['parameters']);
					if($shopName!=false)
					{
						$event['html']='<a href="'.edp_href_link(PAGENAME_USER_INFO, 'uid='.$event['user_id']).'">'.$event['nick'].
						'</a>添加店铺 <a href="'.edp_href_link(PAGENAME_SHOP_INFO,'sid='.$event['parameters']).'">'.
						$shopName.'</a>。';
					}
					break;
				}
				case ADD_PRODUCT:
				{
					$idlist=split(' ',$event['parameters']);
					$shopName=$shopDAO->GetShopName($idlist['0']);
					$productDAO=GetProductDAO();
					$product=$productDAO->GetProductInfo($idlist['1']);
					if($shopName!=false&&$product!=false)
					{
						$event['html']='<a href="'.edp_href_link(PAGENAME_USER_INFO, 'uid='.$event['user_id']).'">'.$event['nick'].
						'</a>添加店铺 <a href="'.edp_href_link(PAGENAME_SHOP_INFO,'sid='.$idlist['0']).'">'.$shopName.'</a>的商品';
						
						if(strlen($product['product_name'])>'20')
							$product['product_name']=EdpSubStr($product['product_name'], '0', '20').'...';
						$event['html']=$event['html'].'<a href="'.edp_href_link(PAGENAME_PRODUCT_INFO,'pid='.$idlist['1']).'">'.
						$product['product_name'].'</a>';
						$event['html']=$event['html'].'。';
					}
					break;
				}
				case ADD_FRIEND:
				{
					$user=$userDAO->GetUserByID($event['parameters']);
					if($user!=false)
					{
						$event['html']='<a href="'.edp_href_link(PAGENAME_USER_INFO, 'uid='.$event['user_id']).'">'.$event['nick'].
						'</a>与用户 <a href="'.edp_href_link(PAGENAME_USER_INFO,'uid='.$event['parameters']).'">'.$user['nick'].'</a> 成为好友。';
					}
					break;
				}
				case COLLECT_SHOP:
				{
					$shopName=$shopDAO->GetShopName($event['parameters']);
					if($shopName!=false)
					{
						$event['html']='<a href="'.edp_href_link(PAGENAME_USER_INFO, 'uid='.$event['user_id']).'">'.$event['nick'].
						'</a>收藏店铺 <a href="'.edp_href_link(PAGENAME_SHOP_INFO,'sid='.$event['parameters']).'">'.
						$shopName.'</a>。';
					}
					break;
				}
				case COLLECT_PRODUCT:
				{
					$idlist=split(' ',$event['parameters']);
					$shopName=$shopDAO->GetShopName($idlist['0']);
					$productDAO=GetProductDAO();
					$product=$productDAO->GetProductInfo($idlist['1']);
					if($shopName!=false&&$product!=false)
					{
						$event['html']='<a href="'.edp_href_link(PAGENAME_USER_INFO, 'uid='.$event['user_id']).'">'.$event['nick'].
						'</a>收藏店铺 <a href="'.edp_href_link(PAGENAME_SHOP_INFO,'sid='.$idlist['0']).'">'.$shopName.'</a>的商品';
						
						if(strlen($product['product_name'])>'20')
							$product['product_name']=EdpSubStr($product['product_name'], '0', '20').'...';
						$event['html']=$event['html'].'<a href="'.edp_href_link(PAGENAME_PRODUCT_INFO,'pid='.$idlist['1']).'">'.
						$product['product_name'].'</a>';
						$event['html']=$event['html'].'。';
					}
					break;
				}

				case MODIFY_SHOP:
				{
					$shopName = $shopDAO->GetShopName($event['parameters']);
					if($shopName!=false)
					{
						$event['html']='修改店铺 <a href="'.edp_href_link(PAGENAME_SHOP_INFO,'sid='.$event['parameters']).'">'.
						$shopName.'</a> 的简介。';
					}
					break;
				}				
				default:
				{
					$event['html']='';
					break;
				}
			}
			$eventList[]=$event;
		}
		
	}
?>